////////////////////////////////////////////////////////////////////////////////
// Copyright 2010 Michael Schmalle - Teoti Graphix, LLC
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0 
// 
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and 
// limitations under the License
// 
// Author: Michael Schmalle, Principal Architect
// mschmalle at teotigraphix dot com
////////////////////////////////////////////////////////////////////////////////

package org.teotigraphix.swizplugin.events
{

import flash.events.Event;

import mx.events.ModuleEvent;
import mx.modules.IModuleInfo;

import org.swizframework.core.IBeanFactory;
import org.teotigraphix.swizplugin.bundles.IBundle;
import org.teotigraphix.swizplugin.services.BundleService;

/**
 * The <strong>BundleServiceEvent</strong> notifies listeners of 
 * <code>IBundleService</code> events.
 * 
 * @author Michael Schmalle
 */
public class BundleServiceEvent extends Event
{
	//--------------------------------------------------------------------------
	//
	//  Public :: Constants
	//
	//--------------------------------------------------------------------------
	
	/**
	 * Dispatched when an <code>IBundleService</code> has been initialized.
	 * 
	 * <p>When this event is dispatched, the bundles have had their activators
	 * created but <code>start()</code> has not been called yet.</p>
	 * 
	 * @bundleServiceInitialized
	 */
	public static const BUNDLE_SERVICE_INITIALIZED:String = "bundleServiceInitialized";
	
	/**
	 * Dispatched when an <code>IBundleService</code> has been started.
	 * 
	 * <p>When this event is dispatched, the extension registry has been completly
	 * populated with it's plugins and can be read correctly.</p>
	 * 
	 * @bundleServiceStarted
	 */
	public static const BUNDLE_SERVICE_STARTED:String = "bundleServiceStarted";
	
	/**
	 * Dispatched when an <code>IBundle</code> has been added to the 
	 * <code>IBundleService</code>.
	 * 
	 * @bundleAdd
	 */
	public static const BUNDLE_ADD:String = "bundleAdd";
	
	/**
	 * Dispatched when an <code>IBundle</code> has been removed from the 
	 * <code>IBundleService</code>.
	 * 
	 * @bundleRemove
	 */
	public static const BUNDLE_REMOVE:String = "bundleRemove";
	
	/**
	 * Dispatched when a request to load a bundle by url has been requested.
	 * 
	 * @bundleLoadRequested
	 */
	public static const BUNDLE_LOAD_REQUESTED:String = "bundleLoadRequested";
	
	/**
	 * Dispatched when a bundle has completed it's loading and has been added
	 * to the <code>IBundleService</code>.
	 * 
	 * @bundleLoadComplete
	 */
	public static const BUNDLE_LOAD_COMPLETE:String = "bundleLoadComplete";
	
	/**
	 * Dispatched when a bundle has been setup by the module manager.
	 * 
	 * @bundleLoadSetup
	 */
	public static const BUNDLE_LOAD_SETUP:String = "bundleLoadSetup";
	
	/**
	 * Dispatched when a bundle has had it's progress updated during loading.
	 * 
	 * @bundleLoadProgress
	 */
	public static const BUNDLE_LOAD_PROGRESS:String = "bundleLoadProgress";
	
	/**
	 * Dispatched when a bundle has had an error during it's loading.
	 * 
	 * @bundleLoadError
	 */
	public static const BUNDLE_LOAD_ERROR:String = "bundleLoadError";
	
	//--------------------------------------------------------------------------
	//
	//  Public :: Variables
	//
	//--------------------------------------------------------------------------
	
	/**
	 * The <code>IBundle</code>.
	 */
	public var bundle:IBundle;
	
	/**
	 * The <code>ModuleEvent</code>.
	 */
	public var moduleEvent:ModuleEvent;
	
	//--------------------------------------------------------------------------
	//
	//  Constructor
	//
	//--------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 * 
	 * @param type A String indicating the type of event.
	 * @param bundle The <code>IBundle</code>.
	 */
	public function BundleServiceEvent(type:String, bundle:IBundle = null)
	{
		super(type);
		
		this.bundle = bundle;
	}
	
	//--------------------------------------------------------------------------
	//
	//  Overridden Public :: Methods
	//
	//--------------------------------------------------------------------------
	
	/**
	 * @private
	 */
	override public function clone():Event
	{
		var e:BundleServiceEvent = new BundleServiceEvent(type, bundle);
		e.moduleEvent = moduleEvent;
		return e;
	}
}
}